package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

@RestControllerAdvice
public class MyExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Result exceptionHandler(Exception e){
        System.out.println("通用异常");
        Result result = Result.fail();
        result.setMessage(e.getMessage());
        e.printStackTrace();
        return result;
    }

    @ExceptionHandler(IllegalArgumentException.class)
    public Result illegalArgumentExceptionHandler(IllegalArgumentException e){
        System.out.println("非法参数异常");
        Result result = Result.fail();
        result.setMessage(e.getMessage());
        return result;
    }

    @ExceptionHandler(ArithmeticException.class)
    public Result arithmeticExceptionHandler(ArithmeticException e){
        System.out.println("数学运算异常");
        Result result = Result.fail();
        result.setMessage(e.getMessage());
        return result;
    }


    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public Result maxUploadSizeExceededException(MaxUploadSizeExceededException e){
        System.out.println("文件超出范围异常");
        Result result = Result.fail();
        result.setMessage(e.getMessage());
        return result;
    }


    @ExceptionHandler(MyException.class)
    public Result myIllegalArgumentException(MyException e){
        System.out.println("业务自定义异常");
        Result result = Result.fail();
        result.setMessage(e.getMessage());
        return result;
    }


}
